import { createStore } from "./redux";

// actions
// 同步action
export const incrementAction = (val) => ({ type: "increment", payload: val });
export const decrementAction = (val) => ({ type: "decrement", payload: val });
// 异步action

// reducers
const counterReducer = function (prevState = 0, action) {
  // prevState 之前的状态
  // action action对象 { type: 'xxx', payload: xxx }
  switch (action.type) {
    case "increment":
      return prevState + action.payload;
    case "decrement":
      return prevState - action.payload;
    default:
      return prevState;
  }
};

// store
export default createStore(counterReducer);
